package com.qk.mapper;

import com.qk.dto.UserDto;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    List<User> listUsers(UserDto userDto);

    @Insert("insert into user (username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time) " +
            "values (#{username},#{password},#{name},#{phone},#{email},#{gender},#{status},#{deptId},#{roleId},#{image},#{remark},#{createTime},#{updateTime})")
    void addUser(User user);

    void deleteByIds(List<Integer> ids);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user where id = #{id}")
    User getById(Integer id);

    void updateUser(User user);

    @Select("select id, username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time from user")
    List<User> listAll();

    @Select("select u.* from user u join role r on u.role_id = r.id where r.label = #{roleLabel} and u.status = 1")
    List<User> listUserByRole(String roleLabel);

    @Select("select u.* from user u join dept d on u.dept_id = d.id where d.id = #{deptId}")
    List<User> ListUserByDept(Integer deptId);

    @Select("select u.*,r.label role_label from user u left join role r on u.role_id = r.id where u.username = #{username}")
    User getByUsername(String username);
}
